/** A class which makes directions from a PathRoute using a TraceStrategy.
    It creates a string which contains these directions.
    @author Ian Helmke, Dan King
*/
public class DirectionMaker implements TraceStrategy<City, Route, String> {
  /** Represents the directions for getting from the start of a path to the
      destination.
  */
  private String directions = "";

  /** The constructor. */
  public DirectionMaker(){}


  /** Initializes (or reinitializes) this tracer to its default state. This allows
      the same tracer to be used in many different paths, without needing to create
      a new instance of the tracer for each one.
  */
  public void initTracer() {
    this.directions = "";
  }

  /** Handles the reciept of a node on a path. Nodes are visited in sequential
      order and may be hit more than once, depending on the path.
      @param node The current node of the route.
  */
  public void handleNode(INode<City, Route> node) {
    directions = directions.concat("Enter " + node.getInfo().getName() + ".\n");
  }

  /** Handles the reciept of a link on a path. Links are visited in sequential
      order and may be hit more than once, depending on the path.
      @param link The current link of the route.
  */
  public void handleLink(ILink<Route, City> link) {
    directions = directions.concat("Travel " + link.getInfo().getWeightedDistance() +
                                   " miles. \n");
  }

  /** Returns the result of this tracer, having visited all applicable nodes
      and routes.
      @return The product of type T generated by this TraceStrategy.
  */
  public String returnProduct() {
    directions = directions.concat("You have arrived at your destination.");
    
    return directions;
  }
}